<template>
	<view class="u-page">
		<view class="u-demo-block">
			<view class="u-demo-block__content">
				<view class="u-page__tag-item">
					<u-search v-model="searchKeyword"></u-search>
				</view>
			</view>
		</view>
		<u-list @scrolltolower="list" >
			<u-list-item v-for="(item, index) in dataList" :key="index">
				<u-cell-group>
					<u-cell :label="item.username + ' ' + item.deptName" :title="item.nickname" :isLink="true"
						:url="editItem(item.id)">
						<u-avatar slot="icon" shape="square" size="35" :src="item.url"
							customStyle="margin: -3px 5px -3px 0"></u-avatar>
					</u-cell>
				</u-cell-group>
			</u-list-item>
		</u-list>
		<view class="add-btn" @click="addItem">
			<text>+</text>
		</view>
	</view>
</template>
<script>
	import {
		page
	} from "@/api/users/users.js"
	export default {

		data() {
			return {
				searchKeyword: '',
				dataList: [],
				pageNo: 1,
				pageSize: 5
			}
		},
		computed: {

		},
		onLoad() {
			this.list();
		},
		methods: {
			list() {
				const param = {
					"pageNo": this.pageNo,
					"pageSize": this.pageSize
				}
				page(param).then(response => {
					const newData = response.data.list || [];
					if (newData.length > 0) {
						this.dataList = this.dataList.concat(newData);
						this.pageNo++;
					}
				})
			},
			scrolltolower() {
				this.list();
			},
			goBack() {
				uni.navigateBack()
			},
			handleSearch() {
				// 搜索逻辑已在computed中实现
			},
			addItem() {
				uni.navigateTo({
					url: '/pages/users/detail?action=add'
				})
			},
			editItem(item) {
				if (item) {
					return `/pages/users/detail?action=edit&id=${item.id}`
				}
			}
		}
	}
</script>

<style lang="scss">


</style>